package com.ocp.socket.server.mina;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import java.nio.charset.Charset;

/**
 * @Auther: zhangzh
 * @Date: 2019/1/23 18:29
 * @Description: 自定义解编码器工厂
 * @Version: 1.0.0
 */

public class ByteArrayCodecFactory implements ProtocolCodecFactory {

    private ByteArrayDecoder decoder;

    private ByteArrayEncoder encoder;

    public ByteArrayCodecFactory() {

        this(Charset.defaultCharset());

    }

    public ByteArrayCodecFactory(Charset charSet) {

        encoder = new ByteArrayEncoder(charSet);

        decoder = new ByteArrayDecoder(charSet);

    }

    @Override

    public ProtocolDecoder getDecoder(IoSession session) throws Exception {

        return decoder;

    }

    @Override

    public ProtocolEncoder getEncoder(IoSession session) throws Exception {

        return encoder;

    } }
